package ass2;

public class Game {

	boolean EnableGui;
	int EpisodeToPlay;
	int MaximumTurns;
	int BoardSize;

	public static void main( String[] args ) {
		int totalconverge = 0;
		Game game = new Game(false, 10000, 1000, 11);
		float avgturns = game.playEpisodes();
		totalconverge += avgturns;
		System.out.println("Average converge: "+ (float) ((float)totalconverge/100f));
	}

	public Game(boolean enableGui, int gamesamount, int maxturns, int boardSize) {
		EnableGui = enableGui;
		EpisodeToPlay = gamesamount;
		MaximumTurns = maxturns;
		BoardSize = boardSize;
	}

	public float playEpisodes() {
		int totalturns = 0;
		Gui gui = new Gui(EnableGui);
		Environment env = new Environment(MaximumTurns, BoardSize, 0.5f, 0.5f, 0.01f);
		env.spawnPredator(new Location(0,0), "Q");
		env.spawnPrey(new Location(5,5));

		for(int episode = 0; episode < EpisodeToPlay; episode++) {
			if(gui.Enabled) {
				gui.setEnvironment(env);
			}
			int amountofturns = env.playGame(gui);
			//System.out.println(amountofturns );
			totalturns += amountofturns;
			env.reset();
			
			
		}
		Tools.printQ(env.getPredator().Q);
		float averageturns = (float)totalturns/(float)EpisodeToPlay;
		return averageturns;
	}
}
